package com.rongke.service.impl;

import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.rongke.mapper.SelectSpecifMapper;
import com.rongke.model.SelectSpecif;
import com.rongke.service.SelectSpecifService;
import com.rongke.utils.StringUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.*;

/**
 * @SelectSpecifServiceImpl
 * @定制商品规格表 ServiceImpl
 * @version : Ver 1.0
 */
@Service
public class SelectSpecifServiceImpl extends ServiceImpl<SelectSpecifMapper, SelectSpecif> implements SelectSpecifService {
    @Autowired
    private  SelectSpecifMapper selectSpecifMapper;
    /**
     *
     * @param sgId  定制商品id
     * @return  根据定制商品id查询该商品所有规格（规格去重）
     */
    @Override
    public Map selectListBysgId(Long sgId) {
        List<Map> maps=selectSpecifMapper.selectListBysgId(sgId);
        //对规格去重
        Map ssm=new HashMap();
        Map index=maps.get(0);
        ssm.put("goodsName",index.get("goodsName"));
        ssm.put("mPrice",index.get("mPrice"));
        ssm.put("otherPrice",index.get("otherPrice"));
        ssm.put("returnRate",index.get("returnRate"));
        ssm.put("goodsType",index.get("goodsType"));
        ssm.put("picUrl",index.get("picUrl"));
        Set<String> fn=new HashSet<>();
        Set<String> hotel=new HashSet<>();
        for (Map map: maps) {
            if(StringUtil.isNotEmpty(String.valueOf(map.get("foodNeed")))){
                fn.add(String.valueOf(map.get("foodNeed")));
            }
            if(StringUtil.isNotEmpty(String.valueOf(map.get("hotel")))){
                hotel.add(String.valueOf(map.get("hotel")));
            }
        }
        Map specif=new HashMap();
        specif.put("foodNeed",fn);
        specif.put("hotel",hotel);
        ssm.put("selectSpecif",specif);
        return ssm;
    }

}
